package cn.xfdzx.android.apps.shop.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;

import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.activity.ShopActivity;
import cn.xfdzx.android.apps.shop.contract.NearClickListener;
import cn.xfdzx.android.apps.shop.view.CheckableTextView;

/**
 * @author gzk
 * @date 2020/3/28 0028
 * description：首页附近商店操作界面
 */
public class HomeShopViewHolder extends RecyclerView.ViewHolder {

    @BindView(R.id.tv_home_shop_comprehensive_sequencing)
    CheckableTextView tvHomeShopComprehensiveSequencing;//综合排序
    @BindView(R.id.tv_home_shop_sales)
    CheckableTextView tvHomeShopSales;//销量
    @BindView(R.id.tv_home_shop_distance)
    CheckableTextView tvHomeShopDistance;//距离
    @BindView(R.id.tv_home_shop_breaks_the_freight)
    CheckableTextView tvHomeShopBreaksTheFreight;//减免运费
    @BindView(R.id.tv_home_shop_high_quality_stores)
    CheckableTextView tvHomeShopHighQualityStores;//优质门店
    @BindView(R.id.tv_home_shop_members_red_envelope)
    CheckableTextView tvHomeShopMembersRedEnvelope;//会员红包
    @BindView(R.id.tv_home_shop_comments_high_marks)
    CheckableTextView tvHomeShopCommentsHighMarks;//点评高分
    @BindView(R.id.rv_shops)
    RecyclerView rvShops;//底部门店列表

    private Context mContext;
    private boolean isComprehensiveSequencing = true;
    private boolean isSales = false;
    private boolean isDistance = false;

    private boolean isBreaksTheFreight = false;
    private boolean isHighQualityStores = false;
    private boolean isMembersRedEnvelope = false;
    private boolean isCommentsHighMarks = false;
    public HomeNearShopAdapter homeNearShopAdapter;
    private NearClickListener nearClickListener;

    public HomeShopViewHolder(Context mContext, View itemView) {
        super(itemView);
        ButterKnife.bind(this, itemView);
        this.mContext = mContext;

        setDefult();
    }


    public void setDefult() {
        public_set();
        tvHomeShopBreaksTheFreight.setChecked(isBreaksTheFreight);
        tvHomeShopHighQualityStores.setChecked(isHighQualityStores);
        tvHomeShopMembersRedEnvelope.setChecked(isMembersRedEnvelope);
        tvHomeShopCommentsHighMarks.setChecked(isCommentsHighMarks);


        rvShops.setLayoutManager(new LinearLayoutManager(mContext));
        rvShops.setNestedScrollingEnabled(false);
        rvShops.setItemAnimator(new DefaultItemAnimator());
        homeNearShopAdapter = new HomeNearShopAdapter(mContext);

        rvShops.setAdapter(homeNearShopAdapter);
    }

    @OnClick({R.id.tv_home_shop_comprehensive_sequencing, R.id.tv_home_shop_sales, R.id.tv_home_shop_distance, R.id.tv_home_shop_breaks_the_freight, R.id.tv_home_shop_high_quality_stores, R.id.tv_home_shop_members_red_envelope, R.id.tv_home_shop_comments_high_marks})
    public void onTvTwo(View view) {
        switch (view.getId()) {
            case R.id.tv_home_shop_comprehensive_sequencing://综合排序
                if (!isComprehensiveSequencing) {
                    isComprehensiveSequencing = true;
                    isSales = false;
                    isDistance = false;
                    public_set();
                    nearClickListener.onItemClick(1);
                }
                break;
            case R.id.tv_home_shop_sales://销量
                if (!isSales) {
                    isComprehensiveSequencing = false;
                    isSales = true;
                    isDistance = false;
                    public_set();
                    nearClickListener.onItemClick(2);
                }
                break;
            case R.id.tv_home_shop_distance://距离
                if (!isDistance) {
                    isComprehensiveSequencing = false;
                    isSales = false;
                    isDistance = true;
                    public_set();
                    nearClickListener.onItemClick(3);
                }
                break;

            case R.id.tv_home_shop_breaks_the_freight://减免运费
                isBreaksTheFreight = !isBreaksTheFreight;
                tvHomeShopBreaksTheFreight.setChecked(isBreaksTheFreight);
                nearClickListener.onItemClick(4);
                break;
            case R.id.tv_home_shop_high_quality_stores://优质门店
                isHighQualityStores = !isHighQualityStores;
                tvHomeShopHighQualityStores.setChecked(isHighQualityStores);
                nearClickListener.onItemClick(5);
                break;
            case R.id.tv_home_shop_members_red_envelope://会员红包
                isMembersRedEnvelope = !isMembersRedEnvelope;
                tvHomeShopMembersRedEnvelope.setChecked(isMembersRedEnvelope);
                nearClickListener.onItemClick(6);
                break;
            case R.id.tv_home_shop_comments_high_marks://点评高分
                isCommentsHighMarks = !isCommentsHighMarks;
                tvHomeShopCommentsHighMarks.setChecked(isCommentsHighMarks);
                nearClickListener.onItemClick(7);
                break;
        }
    }

    private void public_set() {
        tvHomeShopComprehensiveSequencing.setChecked(isComprehensiveSequencing);
        tvHomeShopSales.setChecked(isSales);
        tvHomeShopDistance.setChecked(isDistance);
    }


    public void setNearClickListener(NearClickListener clickListener){
        nearClickListener=clickListener;
    }
}
